package com.zhongyu.controller;

import com.zhongyu.pojo.Order;
import com.zhongyu.pojo.OrderDetail;
import com.zhongyu.pojo.Org;
import com.zhongyu.pojo.StoreDetail;
import com.zhongyu.service.OrderDetailService;
import com.zhongyu.service.RukuService;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/caiGou/ruku/")
public class RukuController {

    @Resource
    private RukuService rukuService;
    @Resource
    private OrderDetailService orderDetailService;

    @GetMapping("/search/{pageNo}/{pageSize}")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize){
        PageResult pageResult=rukuService.searchAll(pageNo, pageSize);
        return ResultVo.success(pageResult);
    }

    @GetMapping("/search")
    public ResultVo search(Integer id){
        List<Order> pageResult=rukuService.searchAll(id);
        return ResultVo.success(pageResult);
    }

    @GetMapping("/searchAll")
    public ResultVo searchAll(Integer id){
        List<Order> pageResult=rukuService.search(id);
        return ResultVo.success(pageResult);
    }
    @GetMapping("/searchRu")
    public ResultVo searchRu(Integer id){
        System.out.println(id);
        OrderDetail pageResult=orderDetailService.searchRu(id);
        return ResultVo.success(pageResult);
    }
    @PostMapping("/add")
    public ResultVo add(@RequestBody StoreDetail storeDetail, HttpSession session){
        try {

            System.out.println(storeDetail);
             orderDetailService.add(storeDetail,session);
            return ResultVo.success("入库成功！");
        }catch (Exception ex){
            return ResultVo.failure("入库失败！",ex);
        }
    }

}
